<?php

class AppController extends Controller
{
	var $helpers = array('Html','Form','othAuth','Javascript', 'Time', 'Text','Cache','Tree','Habtm');
	var $components = array('othAuth','Conf','Session','Openid','Captcha', 'YahooGeo','RequestHandler','FileOps','Ffmpeg');
	
	var $othAuthRestrictions = array('add','edit','delete', CAKE_ADMIN);
	
	/**
	 * Called before view
	 */
	function beforeFilter()
	{
		$auth_conf = array(
			'mode' => 'oth',
			'login_page' => '/users/login',
			'logout_page' => '/users/logout',
			'access_page' => '/',
			'hashkey' => CAKE_SESSION_STRING,
			'noaccess_page' => '/users/noaccess',
			'strict_gid_check' => false,
			'history_active' => true,
			'login_limit' => true,
			'gid_order' => 'DESC');
		
		$this->othAuth->controller = &$this;
		$this->othAuth->init($auth_conf);
		$this->othAuth->check();
	}
	
	function beforeRender()
	{
		$this->set('sitename', $this->Conf->get('general.sitename'));
		$this->set('sitedesc', $this->Conf->get('general.sitedesc'));
		$this->set('siteurl', $this->Conf->get('general.siteurl'));
		$this->set('enable_comments', $this->Conf->get('general.enable_comments'));
		$this->set('enable_captcha', $this->Conf->get('general.enable_captcha'));
		$this->set('video_width', $this->Conf->get('video.width'));
		$this->set('video_height', $this->Conf->get('video.height'));
		$this->set('video_samplerate', $this->Conf->get('video.samplerate'));
		$this->set('video_bitrate', $this->Conf->get('video.bitrate'));			
	}
	
	function afterRender()
	{
		$isAjax = !empty($this->params['isAjax']);

        $view =& ClassRegistry::getObject('view');

        if ($isAjax) {
            // ajax flashMessage handling
            $session =& $this->Session;
            if ($session->check('Message.flash')) {
                $message = $session->read('Message.flash');
                $session->delSessionVar('Message.flash');
                $message = preg_replace('/<div[^>]*>/i', '', $message);
                $message = preg_replace('/<\/div[^>]*>/i', '', $message);

                $_flash = '$("#flashMessage").html("'.$message.'").css("display", "block");';
            }
		}	
	}
	
	function captcha()
    {
        $this->Captcha->render();
    }
	
}

?>